var http=require('http')
var fs=require('fs')
var path=require('path')
var argv=process.argv;

http.createServer((req,res)=>{
    res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'})
    var getin=argv[2]
    var filePath=path.join(__dirname,"/"+getin)
    var fileReader1=path.join(__dirname,"/fileReader1.js")

    var readable=fs.createReadStream(filePath)
    var readable1=fs.createReadStream(fileReader1)

    if(getin==null){
        readable.on('data',function(chunk){
            res.end(chunk.toString('utf-8'))
        })
    }else{
        fs.access(getin,fs.constants.F_OK,(err)=>{//判断当前目录中是否存在
            if(!err){
                readable1.on('data',function(chunk){
                    res.end(chunk.toString('utf-8'))
                })
            }else{
                console.log('该文件不在该目录下')
            }
        })
    }
}).listen(8081)